<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  <link rel="stylesheet" href="mocha.css"/>
</head>
<body>
  <!-- Required for browser reporter -->
  <div id="mocha"></div>

  <!-- mocha -->
  <script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="js/mocha_setup.js" type="text/javascript"></script>

  <!-- Include your assertion lib of choice -->
  <script src="../node_modules/chai/chai.js" type="text/javascript" ></script>
  <script src="js/sinon.js" type="text/javascript" ></script>
  <script src="js/modernizr.js" type="text/javascript" ></script>
  <script src="js/chai_helpers.js" type="text/javascript" ></script>
  <script src="js/p5_helpers.js" type="text/javascript" ></script>

    <!-- Include anything you want to test -->
    <script src="../lib/p5-test.js" type="text/javascript"></script>

  <!-- Spec files (Now centralised in unit/spec.js) -->
  <script src="unit/spec.js" type="text/javascript" ></script>

  <!-- run mocha -->
  <script type="text/javascript" >
    p5._throwValidationErrors = true;

    window.addEventListener('load', function() {
      var runner = mocha.run();

      // NOTE: Sauce Labs removed, keeping these for now
      // This exposes our test results to Sauce Labs. For more
      // details, see: https://github.com/axemclion/grunt-saucelabs.

      var failedTests = [];
      runner.on('end', function(){
        window.mochaResults = runner.stats;
        window.mochaResults.reports = failedTests;
      });

      runner.on('fail', logFailure);

      function logFailure(test, err) {
        var flattenTitles = function(test){
          var titles = [];
          while (test.parent.title){
            titles.push(test.parent.title);
            test = test.parent;
          }
          return titles.reverse();
        };

        failedTests.push({
          name: test.title,
          result: false,
          message: err.message,
          stack: err.stack,
          titles: flattenTitles(test)
        });
      }
    }, false);
  </script>
</body>
</html>
